import Vue from 'vue'
import Router from 'vue-router'
import axios from 'axios'
import Login from "../components/Login.vue";
import VueRouter from "vue-router";
import Doctor from "../components/Doctor.vue";
import Manager from "../components/Manager.vue";
import Patient from "../components/Community.vue";
import Community from "../components/Community.vue";
import DiagnosticManagement from "../components/DiagnosticManagement.vue";

Vue.config.productionTip = false
Vue.use(VueRouter)

let rou = new Router({
  routes: [
    {
      path: '/',
      name: 'Login',
      component: Login
    },
    {
      path: '/doctor',
      name: 'Doctor',
      component: Doctor
    },
    {
      path: '/community',
      name: 'Community',
      component: Community
    },
    {
      path: '/diagnosticManagement',
      name: 'DiagnosticManagement',
      component: DiagnosticManagement
    },
    {
      path: '/manager',
      name: 'Manager',
      component: Manager
    }
  ]
});
rou.beforeEach((to, from, next) => {
  if (to.path==='/'|| to.path==='/userLogin' ||to.path==='/phonePwd'||to.path==='/password'||to.path==='/addUser'){
    return next();
  }
  let item = window.sessionStorage.getItem('token')
  if (item){
    axios.defaults.headers.common['token']=item
    return next();
  }
  alert('请登录')
  return next('/')
  // window.sessionStorage.setItem("token",res.data.data.token)
})

export default rou

